
*************************
*** CODE FOR KFF DATA ***
*************************


clear
cd "/Users/samtrachtman/Dropbox/ACA Study/Projects/Public Private Field Experiment/APSR production/replication materials/submission_data/kff"
set matsize 800
set more off

use modified_trend_thru1216, clear

********************************
** CLEANING AND PREPPING DATA **
********************************

	*recoding insurance status 
	gen insurance2 = 1 if insurance==1
	replace insurance2 = 0 if insurance==2

	*recoding age and dropping over-64's
	gen age2 = age
	replace age2=. if age==99
	drop if age2 > 64 

	*recoding political party 
	gen party3 = 1 if partyid==2
	replace party3 = 2 if partyid==3
	replace party3 = 3 if partyid==1
	gen party5new = party5
	replace party5new = . if party5==9

	*coding leaners as partisans 
	gen party3new = 1 if party5new==1 | party5new==2
	replace party3new =2 if party5new==3
	replace party3new = 3 if party5new==4 | party5new==5

	*recoding education 
	gen ed = 1 if receduc2==1 | receduc==1| receduc==2
	replace ed = 2 if receduc2==2 | receduc==3
	replace ed = 3 if receduc2==3 | receduc==4

	*recoding income 
	gen income2 = income
	replace income2 = . if income==9

	*recoding employment 
	gen empl = 1 if employment2==1 | employment==2
	replace empl = 2 if employment2==2 | employment==3
	replace empl = 3 if employment2==3 | employment2==4 | employment==5
	replace empl = 4 if employment2==5 | employment==7
	replace empl = 5 if employment2==6 | employment==4 
	replace empl = 6 if employment2==7 | employment==8
	replace empl = 7 if employment2==8 | employment==6
	replace empl = 8 if employment==1
	replace empl = 9 if employment2==9 | employment==9

	*recoding employment fewer categories
	gen empl2 = 1 if empl==1 | empl==2
	replace empl2 = 2 if empl==5
	replace empl2 = 3 if empl==3
	replace empl2 = 4 if empl2==.
	//empl2 = 1 is fulltime or parttime work, empl2 = 2 is retired, empl2 = 3 is unemployment (seeking), empl2 = 4 is all the rest 

	*recoding race
	replace racethn = 1 if racethn == 9

	*partisan labels, with true independents as .
	gen republican = 1 if party3new==3
	replace republican = 0 if party3new==1

	*dropping responses for dates prior to asking indivinsur2
	drop if date < 45

	*coding dependent variable
	gen final_ins = "uninsured" if insurance2 == 0
	replace final_ins = "ESI" if insurance2 == 1 & coverage ==1 | coverage == 2
	replace final_ins = "marketplace" if insurance2 == 1 & indivinsur2 == 2
	replace final_ins = "private" if insurance2 == 1 & indivinsur2==1 | indivinsur2==4 

	gen ins = 1 if final_ins == "uninsured"
	replace ins = 2 if final_ins == "ESI"
	replace ins = 3 if final_ins == "marketplace"
	replace ins = 4 if final_ins == "private"

	*setting state fixed effects vbl 
	tab state, gen(state2)

	*recoding ideology
	gen ideo2 = ideology if ideology != 9

	*save data
	save temp_analysis_data, replace 

	*import and merge in data on ffm-sbm state level
	import excel "/Users/samtrachtman/Dropbox/ACA Study/Projects/Public Private Field Experiment/data and do-files/kaiser data and do-files/Kaiser Analysis/state_ffm_sbm.xlsx", sheet("Sheet1") firstrow clear
	rename FIPSCode state
	merge 1:m state using temp_analysis_data
	gen ffm = 1 if type_2016 == "FFM" | type_2016 == "Partnership"
	replace ffm = 0 if type_2016 == "SBM"

	*calculating percent of dems vs. reps before cutting out those with ESI 
	tab party3new

	*dropping those with ESI 
	drop if ins == 2 
	tab party3new

*************************************************************
** REGRESSIONS PRODUCING RESULTS FOR FIGURE 2 AND TABLE A2 **
*************************************************************

cd "/Users/samtrachtman/Dropbox/ACA Study/Projects/Public Private Field Experiment/APSR production/replication materials/submission_output/kff"
	
	*regression producing results for likelihood of uninsured
	mlogit ins i.republican ffm republican#ffm  age2 i.ed i.racethn i.income2 i.sex i.state i.empl2 i.date, rrr base(1) 
	margins, dydx(republican racethn income2 empl2 sex ed) pr(out(1)) post
	matrix output1 = r(table)'
	putexcel set stata_raw_output, sheet("uninsured", replace) modify
	putexcel A1 = matrix(output1), names 

	*regression producing results for likelihood of marketplace
	mlogit ins i.republican ffm republican#ffm age2 i.ed i.racethn i.income2 i.sex i.state i.empl2 i.date, rrr base(1) 
	margins, dydx(republican racethn income2 empl2 sex ed) pr(out(3)) post
	matrix output3 = r(table)'
	putexcel set stata_raw_output, sheet("marketplace", replace) modify
	putexcel A1 = matrix(output3), names 

	*regression producing results for likelihood of private
	mlogit ins i.republican ffm republican#ffm age2 i.ed i.racethn i.income2 i.sex i.state i.empl2 i.date, rrr base(1) 
	margins, dydx(republican racethn income2 empl2 sex ed) pr(out(4)) post
	matrix output4 = r(table)'
	putexcel set stata_raw_output, sheet("private", replace) modify
	putexcel A1 = matrix(output4), names 

**************
** TABLE A3 **
**************

	*With ideology as main predictor
	mlogit ins i.ideo2 ffm age2 i.ed i.racethn i.income2 i.sex i.state i.empl2 i.date, rrr base(1) 
	margins, dydx(ideo2 racethn income2 empl2 sex ed) pr(out(1)) post
	matrix output1 = r(table)'
	putexcel set stata_raw_output2, sheet("uninsured", replace) modify
	putexcel A1 = matrix(output1), names 

	mlogit ins i.ideo2 ffm age2 i.ed i.racethn i.income2 i.sex i.state i.empl2 i.date, rrr base(1) 
	margins, dydx(ideo2 racethn income2 empl2 sex ed) pr(out(3)) post
	matrix output3 = r(table)'
	putexcel set stata_raw_output2, sheet("marketplace", replace) modify
	putexcel A1 = matrix(output3), names 
	
	mlogit ins i.ideo2 ffm age2 i.ed i.racethn i.income2 i.sex i.state i.empl2 i.date, rrr base(1) 
	margins, dydx(ideo2 racethn income2 empl2 sex ed) pr(out(4)) post
	matrix output4 = r(table)'
	putexcel set stata_raw_output2, sheet("private", replace) modify
	putexcel A1 = matrix(output4), names 

	*Controlling for ideology
	mlogit ins i.republican i.ideo2 ffm republican#ffm age2 i.ed i.racethn i.income2 i.sex i.state i.empl2 i.date, rrr base(1) 
	margins, dydx(republican ideo2 racethn income2 empl2 sex ed) pr(out(1)) post
	matrix output1 = r(table)'
	putexcel set stata_raw_output3, sheet("uninsured", replace) modify
	putexcel A1 = matrix(output1), names 
	
	mlogit ins i.republican i.ideo2 ffm republican#ffm age2 i.ed i.racethn i.income2 i.sex i.state i.empl2 i.date, rrr base(1) 
	margins, dydx(republican ideo2 racethn income2 empl2 sex ed) pr(out(3)) post
	matrix output3 = r(table)'
	putexcel set stata_raw_output3, sheet("marketplace", replace) modify
	putexcel A1 = matrix(output3), names 
	
	mlogit ins i.republican i.ideo2 ffm republican#ffm age2 i.ed i.racethn i.income2 i.sex i.state i.empl2 i.date, rrr base(1) 
	margins, dydx(republican ideo2 racethn income2 empl2 sex ed) pr(out(4)) post
	matrix output4 = r(table)'
	putexcel set stata_raw_output3, sheet("private", replace) modify
	putexcel A1 = matrix(output4), names 

	*Ideology and party interaction 
	mlogit ins i.republican i.ideo2 i.republican#i.ideo2 ffm republican#ffm age2 i.ed i.racethn i.income2 i.sex i.state i.empl2 i.date, rrr base(1) 
	margins, dydx(republican ideo2 racethn income2 empl2 sex ed) pr(out(1)) post
	matrix output1 = r(table)'
	putexcel set stata_raw_output4, sheet("uninsured", replace) modify
	putexcel A1 = matrix(output1), names 
	
	mlogit ins i.republican i.ideo2 i.republican#i.ideo2 ffm republican#ffm age2 i.ed i.racethn i.income2 i.sex i.state i.empl2 i.date, rrr base(1) 
	margins, dydx(republican ideo2 racethn income2 empl2 sex ed) pr(out(3)) post
	matrix output3 = r(table)'
	putexcel set stata_raw_output4, sheet("marketplace", replace) modify
	putexcel A1 = matrix(output3), names 
		
	mlogit ins i.republican i.ideo2 i.republican#i.ideo2 ffm republican#ffm age2 i.ed i.racethn i.income2 i.sex i.state i.empl2 i.date, rrr base(1) 
	margins, dydx(republican ideo2 racethn income2 empl2 sex ed) pr(out(4)) post
	matrix output4 = r(table)'
	putexcel set stata_raw_output4, sheet("private", replace) modify
	putexcel A1 = matrix(output4), names 


****************
** IIA Testing**
****************

	mlogit ins i.republican ffm republican#ffm /*i.ideo2*/ age2 i.ed i.racethn i.income2 i.sex i.state i.empl2 i.date 
	estimates store all

	mlogit ins i.republican ffm republican#ffm /*i.ideo2*/ age2 i.ed i.racethn i.income2 i.sex i.state i.empl2 i.date if ins != 3
	estimates store partial_unins_priv

	mlogit ins i.republican ffm republican#ffm /*i.ideo2*/ age2 i.ed i.racethn i.income2 i.sex i.state i.empl2 i.date if ins != 1
	estimates store partial_priv_mark

	mlogit ins i.republican ffm republican#ffm /*i.ideo2*/ age2 i.ed i.racethn i.income2 i.sex i.state i.empl2 i.date if ins != 4
	estimates store partial_unins_mark

	hausman partial_unins_priv all, alleqs constant
	hausman partial_priv_mark all, alleqs constant
	hausman partial_unins_mark all, alleqs constant


**************
**  Table A1 **
**************

	*coding for having insurance 	
	gen cov = 1 if ins == 3 | ins == 4
	replace cov = 0 if ins == 1
	
	*coding for marketplace
	gen mark = 1 if ins == 3
	replace mark = 0 if ins == 4
	
	*regression of insurance coverage
	logit cov i.republican ffm republican#ffm age2 i.ed i.racethn i.income2 i.sex i.state i.empl2 i.date
	margins, dydx(republican racethn income2 empl2 sex ed) post
	matrix output1 = r(table)'
	putexcel set stata_rob_output, sheet("coverage_decision", replace) modify
	putexcel A1 = matrix(output1), names 

	*regression of marketplace v private conditional on having insurance
	logit mark i.republican ffm republican#ffm /*i.ideo2*/ age2 i.ed i.racethn i.income2 i.sex i.state i.empl2 i.date
	margins, dydx(republican racethn income2 empl2 sex ed) post
	matrix output2 = r(table)'
	putexcel set stata_rob_output, sheet("priv_mark_decision", replace) modify
	putexcel A1 = matrix(output2), names 

	
**************
**  Figure 1 **
**************
cd "/Users/samtrachtman/Dropbox/ACA Study/Projects/Public Private Field Experiment/APSR production/replication materials/submission_data/kff"

	*use updated data file from kff
	use modified_trend_thru1216, clear
	*coding age vbl - dropping if over 64
	gen age2 = age
	replace age2=. if age==99
	drop if age2 > 64 	
	*whether respond that insured 
	gen insurance2 = 1 if insurance==1
	replace insurance2 = 0 if insurance==2	
	*
	preserve
	keep if partyid == 2
	*insurance status by date for Dems 
	bysort date: table insurance2 [pweight = weight]
	*
	restore
	keep if partyid == 1
	*insurance status by date for Dems 
	bysort date: table insurance2 [pweight = weight]
	

	
	
	
	







